package com.yyh.synctool.client.constant;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;

/**
 * 数据库默认配置
 * @author xuan
 * @date 2021/12/13
 */
public enum DB
{   MYSQL("MySQL", "3306", "jdbc:mysql://", "com.mysql.cj.jdbc.Driver"),
    ORACLE("Oracle", "1521", "jdbc:oracle:thin:@", "oracle.jdbc.driver.OracleDriver"),
    SQL_SERVER("SQL Server", "1433", "jdbc:microsoft:sqlserver://", "com.microsoft.sqlserver.jdbc.SQLServerDriver");

    public static DB getInstance(String type) {
        EnumSet<DB> dbs = EnumSet.allOf(DB.class);
        final Iterator<DB> iterator = dbs.iterator();
        while (iterator.hasNext()) {
            DB db = iterator.next();
            if (db.type.equals(type)) {
                return db;
            }
        }
        return null;
    }

    /** 所有数据库类型名称 */
    public static List<String> types() {
        EnumSet<DB> set = EnumSet.allOf(DB.class);
        ArrayList<String> types = new ArrayList();
        for (DB db : set) {
            types.add(db.type);
        }
        return types;
    }

    private String type;
    private String defaultPort;
    private String prefixUrl;
    private String driverName;

    DB(String type, String defaultPort, String prefixUrl, String driverName) {
        this.type = type;
        this.defaultPort = defaultPort;
        this.prefixUrl = prefixUrl;
        this.driverName = driverName;
    }

    public String getType() {
        return type;
    }

    public String getDefaultPort() {
        return defaultPort;
    }

    public String getPrefixUrl() {
        return prefixUrl;
    }

    public String getDriverName() {
        return driverName;
    }
}
